const app = getApp()
Page({
  data: {
    boards: [
      { key: 'in_theaters', title: '近期热映' },
      { key: 'coming_soon', title: '即将上映' },
      { key: 'new_movies', title: '新片榜' },
      { key: 'top250', title: 'Top250' }
      // { key: 'weekly' },
      // { key: 'us_box' },
    ],
    // city: '北京',
    loading: true
  },

  onLoad: function () {
    let _this = this
    // this.setData({
    //   city: app.data.currentCity
    // })
    for (let i = 0, l = this.data.boards.length; i < l; i++) {
      // 获取4个电影榜单列表
      app.douban.findList(this.data.boards[i].key, 1, 8, function (res) {
        // 新片榜无total，从数组获取
        _this.data.boards[i].total = res.data.total || res.data.subjects.length
        _this.data.boards[i].movies = res.data.subjects
        _this.setData({
          boards: _this.data.boards,
          loading: false
        })
      })
    }
  }
})